GetSchoolShootingsAction   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 19
dl 0
loc 19
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A index 0 9 2
1
import { Controller, Inject, UseGuards, Get, Param, NotFoundException } from '@nestjs/common';
2
import { AuthGuard } from '@nestjs/passport';
3
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
4
import { IQueryBus } from 'src/Application/IQueryBus';
5
import { IdDTO } from 'src/Infrastructure/Common/DTO/IdDTO';
6
import { Roles } from 'src/Infrastructure/User/Decorator/Roles';
7
import { RolesGuard } from 'src/Infrastructure/User/Security/RolesGuard';
8
import { UserRole } from 'src/Domain/User/User.entity';
9
import { GetShootingsBySchoolQuery } from 'src/Application/School/Query/Shooting/GetShootingsBySchoolQuery';
10
import { ShootingSummaryView } from 'src/Application/School/View/ShootingSummaryView';
11
12
@Controller('schools')
13
@ApiTags('School shooting')
14
@ApiBearerAuth()
15
@UseGuards(AuthGuard('bearer'), RolesGuard)
16
export class GetSchoolShootingsAction {
17
  constructor(
18
    @Inject('IQueryBus')
19
    private readonly queryBus: IQueryBus
20
  ) {}
21
22
  @Get(':id/shootings')
23
  @Roles(UserRole.PHOTOGRAPHER)
24
  @ApiOperation({ summary: 'Get school shootings' })
25
  public async index(@Param() dto: IdDTO): Promise<ShootingSummaryView[]> {
26
    try {
27
      return await this.queryBus.execute(new GetShootingsBySchoolQuery(dto.id));
28
    } catch (e) {
29
      throw new NotFoundException(e.message);
30
    }
31
  }
32
}
33